﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Bll;
using AspNetCs.Model;
using System.Data;

public partial class Users_memorial : BasePage
{
    protected int id = 0;
    protected Memorial MemorialBll = new Memorial();
    protected memorial_model MemorialModel = new memorial_model();
    protected string notSet = "display:none;";
    protected string play = "display:block;";
    protected string musicPath = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx", "请您登录", true);
        if (!IsPostBack)
        {
            if (Request["id"] != null)
            {
                id = StringHelper.isNumber_int(Request["id"].ToString());
                ViewState["id"] = Request["id"];
            }
            if (id <= 0)
            {
                ShowMsgBack("参数传递错误！");
                Response.End();
            }
            MemorialModel = MemorialBll.GetModel(id);

            MusicBLL musicBLL = new MusicBLL();
            musicBLL.BindSelectedMusic(MemorialModel.MusicId, ddlMusic);

            Base_CurrPath = Base_CurrPath + " >> 会员管理中心 >> 纪念馆管理 >>首页";
            CheckUserExit("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/memorial_master_" + id + ".Aspx", "", true);
        }
        else
        {
            id = StringHelper.isNumber_int(ViewState["id"].ToString());
            MemorialModel = MemorialBll.GetModel(id);
        }
        initMusic();
    }

    public void initMusic()
    {
        if (MemorialModel.MusicId == 0)
        {
            notSet = "display:block;";
            play = "display:none;";
        }
        else
        {
            MusicBLL musicBll = Music_Bll.CreateNew;
            MusicModel musicModel = new MusicModel();
            DataTable dataTable = musicBll.GetDataTable("id=" + MemorialModel.MusicId);
            if (dataTable.Rows.Count > 0)
            {
                musicModel = musicBll.GetModel(dataTable.Rows[0]);
            }
            if (musicModel.MusicType == 0)
            {
                musicPath = "../" + musicModel.MusicPath;
            }
            else
            {
                musicPath = musicModel.MusicPath;
            }
        }
    }

    protected void btnMusic_Click(object sender,EventArgs e)
    {
        int MusicId = StringHelper.isNumber_int(ddlMusic.SelectedValue);
        //if (MusicId > 0)
        //{
            MemorialBll.SetMusic(id, MusicId);
        //}
            Response.Redirect("memorial_master_"+id+".Aspx");
            //initMusic();
    }

    protected string memorialType(Object _id)
    {

        Memorial_Type MemorialTypeBll = new Memorial_Type();


        string Result = "";
        try
        {
            Result = MemorialTypeBll.GetModel(StringHelper.isNumber_int(_id.ToString())).TypeName;
        }
        catch
        {
            Result = "";
        }
        return Result;
    }



    protected void Button2_Click(object sender, EventArgs e)
    {
        memorial_model md = new memorial_model();
        md.Id = id;
        md.IsEncrypt = 0;
        md.GetPwd = "";
        MemorialBll.MemorialPwd_Set(md);
        Response.Redirect("memorial_master_" + id + ".Aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        memorial_model md = new memorial_model();
        md.Id = id;
        md.IsEncrypt = 1;
        md.GetPwd = EncryptString.GetEncrypt(Txt_Pwd.Text.ToString().Trim());
        MemorialBll.MemorialPwd_Set(md);
        Response.Redirect("memorial_master_" + id + ".Aspx");
    }

}

